package cn.school.controller.teacher.evaluation;

import cn.school.common.api.CommonResult;
import cn.school.teacher.evaluation.entity.TeacherEvaluationGrade;
import cn.school.teacher.evaluation.service.TeacherEvaluationGradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Api(tags = "TeacherEvaluationGradeController => 绩效考核结果等级管理")
@RestController
@RequestMapping("/teacher/evaluation/greade")
public class TeacherEvaluationGradeController {
    @Resource
    private TeacherEvaluationGradeService teacherEvaluationGradeService;

    @ApiOperation("/list/{id} => 获取考评方案的结果等级")
    @GetMapping("/list/{id}")
    public CommonResult<List<TeacherEvaluationGrade>> list(@PathVariable("id") Long scheId, Map<String, Object> params) {
        List<TeacherEvaluationGrade> list = this.teacherEvaluationGradeService.listScheId(scheId);
        return CommonResult.success(list);
    }

    @ApiOperation("add => 新增结果等级")
    @PostMapping("/add")
    public CommonResult<TeacherEvaluationGrade> add(@RequestBody TeacherEvaluationGrade teacherEvaluationGrade) {
        this.teacherEvaluationGradeService.saveOrUpdateBiz(teacherEvaluationGrade);
        return CommonResult.success();
    }


    @ApiOperation("delete => 删除结果等级")
    @DeleteMapping("/deleteByIds/{ids}")
    public CommonResult<List<TeacherEvaluationGrade>> delete(@PathVariable("ids") Long[] ids) {
        if (ids != null && ids.length != 0) {
            List<Long> idList = Arrays.stream(ids).collect(Collectors.toList());
            this.teacherEvaluationGradeService.removeByIds(idList);
        }
        return CommonResult.success();
    }
}
